# match() :从字符串起始位置匹配
import re

print(re.match('www', 'www.niit.com.cn'))
print(re.match('niit', 'www.niit.com.cn'))
print("----------------------------")
# () ：括号表示分组匹配，只会匹配括号中的内容
# (.*) : 贪婪模式,匹配最长的子串
print(re.findall('a(.*)b', 'a123ba123b'))
# (.*?): 非贪婪模式，匹配最短的子串
print(re.findall('a(.*?)b','a123ba123b'))

print(re.findall('(.*)', 'a123ba123b'))
print(re.findall('(.*?)', 'a123ba123b'))

# 课后练习3
my_string = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)',my_string)
print(matched.groups())